ccR.Add_Rotation(
	3,
	"Ankhys_BASIC_Unholy_DK",
	"BASIC Rotation.\n\nMade by Ankhy"
)

function Ankhys_BASIC_Unholy_DK()
	if (ccR.Player.IsInCombat() or (ccR.Player.IsInGroup() and ccR.Target.IsInCombat())) and ccR.Target.Is.Attackable() then
		if ccR.Player.Has.Glyph(59332) and not ccR.Player.Has.Buff("Breath of Sindragosa") then
			if not ccR.Player.HasTalent("Necrotic Plague") and not ccR.Target.HasMyDebuff("Blood Plague") and ccR.Spell.IsReady("Outbreak") then ccR.Cast.Attack("Outbreak") end
			if not ccR.Player.HasTalent("Necrotic Plague") and not ccR.Target.HasMyDebuff("Frost Fever") and ccR.Spell.IsReady("Outbreak") then ccR.Cast.Attack("Outbreak") end
			if ccR.Player.HasTalent("Necrotic Plague") and not ccR.Target.HasMyDebuff("Necrotic Plague") and ccR.Spell.IsReady("Outbreak") then ccR.Cast.Attack("Outbreak") end	
		else	
			if not ccR.Player.HasTalent("Necrotic Plague") and (not ccR.Target.HasMyDebuff("Blood Plague") or ccR.Target.DebuffDuration("Blood Plague","<", 3)) and ccR.Spell.IsReady("Outbreak") then ccR.Cast.Attack("Outbreak") end
			if not ccR.Player.HasTalent("Necrotic Plague") and (not ccR.Target.HasMyDebuff("Frost Fever") or ccR.Target.DebuffDuration("Frost Fever","<", 3)) and ccR.Spell.IsReady("Outbreak") then ccR.Cast.Attack("Outbreak") end
			if ccR.Player.HasTalent("Necrotic Plague") and (not ccR.Target.HasMyDebuff("Necrotic Plague") or ccR.Target.DebuffDuration("Necrotic Plague","<", 1)) and ccR.Spell.IsReady("Outbreak") then ccR.Cast.Attack("Outbreak") end	
			if not ccR.Player.HasTalent("Necrotic Plague") and (not ccR.Target.HasMyDebuff("Blood Plague") or ccR.Target.DebuffDuration("Blood Plague","<", 3)) and ccR.Spell.IsReady("Unholy Blight") then ccR.Cast.Spell("Unholy Blight") end
			if not ccR.Player.HasTalent("Necrotic Plague") and (not ccR.Target.HasMyDebuff("Frost Fever") or ccR.Target.DebuffDuration("Frost Fever","<", 3)) and ccR.Spell.IsReady("Unholy Blight") then ccR.Cast.Spell("Unholy Blight") end
			if ccR.Player.HasTalent("Necrotic Plague") and (not ccR.Target.HasMyDebuff("Necrotic Plague") or ccR.Target.DebuffDuration("Necrotic Plague","<", 1)) and ccR.Spell.IsReady("Unholy Blight") then ccR.Cast.Spell("Unholy Blight") end
			if not ccR.Player.HasTalent("Necrotic Plague") and (not ccR.Target.HasMyDebuff("Blood Plague") or ccR.Target.DebuffDuration("Blood Plague","<", 3)) and ccR.Spell.IsReady("Plague Strike") then ccR.Cast.Attack("Plague Strike") end
			if not ccR.Player.HasTalent("Necrotic Plague") and (not ccR.Target.HasMyDebuff("Frost Fever") or ccR.Target.DebuffDuration("Frost Fever","<", 3)) and ccR.Spell.IsReady("Plague Strike") then ccR.Cast.Attack("Plague Strike") end
			if ccR.Player.HasTalent("Necrotic Plague") and (not ccR.Target.HasMyDebuff("Necrotic Plague") or ccR.Target.DebuffDuration("Necrotic Plague","<", 1)) and ccR.Spell.IsReady("Plague Strike") then ccR.Cast.Attack("Plague Strike") end
		end
		if ccR.Target.Count(8) > 2 and ccR.Spell.IsReady("Death and Decay") then ccR.Cast.AoE("Death and Decay", "target", 30, 8) end
		Plague_Leech()
		if ccR.Spell.Is.Ready("Soul Reaper") and ccR.Target.Health() <= 45 then ccR.Cast.Attack("Soul Reaper") end
		if ccR.Spell.Is.Ready("Blood Tap") and ccR.Player.Has.Talent("Blood Tap") and (ccR.Player.Has.Buff("Blood Charge") and ccR.Player.BuffStacks("Blood Charge") >= 5 and ccR.Spell.Is.Ready("Soul Reaper") and ccR.Target.Health() <= 45 and not ccR.Spell.CanAttack("Soul Reaper")) then if (not select(3, GetRuneCooldown(1)) and not select(3, GetRuneCooldown(2))) or (not select(3, GetRuneCooldown(3)) and not select(3, GetRuneCooldown(4))) or (not select(3, GetRuneCooldown(5)) and not select(3, GetRuneCooldown(6))) then ccR.Cast.Spell("Blood Tap") end end
		if (ccR.Spell.Is.Ready("Outbreak") and (not ccR.Player.Has.Talent("Necrotic Plague") and (not ccR.Unit.DebuffDuration(vUnit, "Frost Fever") or not ccR.Unit.DebuffDuration(vUnit, "Blood Plague"))) or (ccR.Player.Has.Talent("Necrotic Plague") and not ccR.Unit.DebuffDuration(vUnit, "Necrotic Plague"))) then ccR.Cast.Attack("Outbreak") end
		if ccR.Player.Count(8) >= 3 and ccR.Spell.IsReady("Blood Boil") then ccR.Cast.Spell("Blood Boil") end
		if ccR.Player.Count(8) < 3 and ccR.Spell.IsReady("Festering Strike") and ccR.Player.Rune_Count("Blood") > 2 and ccR.Player.Rune_Count("Frost") > 2 then ccR.Cast.Attack("Festering Strike") end
		if ccR.Spell.IsReady("Scourge Strike") and ccR.Player.Rune_Count("Unholy") > 1 then ccR.Cast.Attack("Scourge Strike") end
		if ccR.Spell.IsReady("Dark Transformation") then ccR.Cast.Spell("Dark Transformation") end
		if ccR.Spell.Is.Ready("Blood Tap") and ccR.Player.Has.Talent("Blood Tap") and (ccR.Player.Has.Buff("Blood Charge") and ccR.Player.BuffStacks("Blood Charge") >= 11) then if (not select(3, GetRuneCooldown(1)) and not select(3, GetRuneCooldown(2))) or (not select(3, GetRuneCooldown(3)) and not select(3, GetRuneCooldown(4))) or (not select(3, GetRuneCooldown(5)) and not select(3, GetRuneCooldown(6))) then ccR.Cast.Spell("Blood Tap") end end
		if ccR.Spell.IsReady("Death Coil") and not ccR.Unit.Has.Buff("pet", "Dark Transformation") or ccR.Player.Runic_Power() > 81 then ccR.Cast.Attack("Death Coil") end
		if ccR.Spell.IsReady("Scourge Strike") then ccR.Cast.Attack("Scourge Strike") end
		if ccR.Spell.IsReady("Festering Strike") then ccR.Cast.Attack("Festering Strike") end
		if ccR.Spell.IsReady("Death Coil") and ccR.Player.HasBuff("Sudden Death") then ccR.Cast.Attack("Death Coil") end
		Plague_Leech_Last_Resort()
		if ccR.Spell.Is.Ready("Blood Tap") and ccR.Player.Has.Talent("Blood Tap") and (ccR.Player.Has.Buff("Blood Charge") and ccR.Player.BuffStacks("Blood Charge") >= 5) then if (not select(3, GetRuneCooldown(1)) and not select(3, GetRuneCooldown(2))) or (not select(3, GetRuneCooldown(3)) and not select(3, GetRuneCooldown(4))) or (not select(3, GetRuneCooldown(5)) and not select(3, GetRuneCooldown(6))) then ccR.Cast.Spell("Blood Tap") end end
		if ccR.Player.Count(8) > 0 and ccR.Target.IsBoss() and ccR.Spell.IsReady("Empower Rune Weapon") and ccR.Player.Rune_Count("Blood") < 1 and ccR.Player.Rune_Count("Death") < 2 and ccR.Player.Rune_Count("Frost") < 1 and ccR.Player.Rune_Count("Unholy") < 1 then ccR.Cast.Spell("Empower Rune Weapon") end
	end
end
local function Plague_Leech()
	local vRunesDepleted = 0
	for i= 1, 6 do 
		local start, duration, runeReady = GetRuneCooldown(i)
		if not runeReady and start > 0 and start < GetTime()-(duration/2) then vRunesDepleted = vRunesDepleted + 1 end
		--if not runeReady then vRunesDepleted = vRunesDepleted + 1 end
	end 
	if ccR.Spell.Is.Ready(PLAGUE_LEECH)	 
	and vRunesDepleted >= 2
	then
		for x = 1, #ccR_Enemies_Within_44 do 
			local vUnit = ccR_Enemies_Within_44[x] 
			if (
					(not ccR.Unit.Is.Boss(vUnit) and (ccR.Unit.Has.MyDebuff(vUnit, FROST_FEVER) and ccR.Unit.Has.MyDebuff(vUnit, BLOOD_PLAGUE)) or ccR.Unit.Has.MyDebuff(vUnit, NECROTIC_PLAGUE_DEBUFF))
					or
					(ccR.Unit.Is.Boss(vUnit) and (ccR.Unit.Has.MyDebuff(vUnit, FROST_FEVER) and ccR.Unit.MyDebuffDuration(vUnit, BLOOD_PLAGUE, "<=", 10)) or ccR.Unit.MyDebuffDuration(vUnit, NECROTIC_PLAGUE_DEBUFF, "<=", 10))
				)
			and ccR.Spell.CanAttack(PLAGUE_LEECH, vUnit) 
			and ccR.Player.Is.Facing(vUnit)
			then 
				ccR.Cast.Attack(PLAGUE_LEECH, vUnit)
			end
		end
	end
end
local function Plague_Leech_Last_Resort()
	local vRunesDepleted = 0
	for i= 1, 6 do 
		local start, duration, runeReady = GetRuneCooldown(i)
		if not runeReady and start > 0 and start < GetTime()-(duration/2) then vRunesDepleted = vRunesDepleted + 1 end
		--if not runeReady then vRunesDepleted = vRunesDepleted + 1 end
	end 
	if ccR.Spell.Is.Ready(PLAGUE_LEECH)	 
	and vRunesDepleted >= 2
	then
		for x = 1, #ccR_Enemies_Within_44 do 
			local vUnit = ccR_Enemies_Within_44[x] 
			if (ccR.Unit.Has.MyDebuff(vUnit, FROST_FEVER) and ccR.Unit.Has.MyDebuff(vUnit, BLOOD_PLAGUE) or ccR.Unit.Has.MyDebuff(vUnit, NECROTIC_PLAGUE_DEBUFF))
			and ccR.Spell.CanAttack(PLAGUE_LEECH, vUnit) 
			and ccR.Player.Is.Facing(vUnit)
			then 
				ccR.Cast.Attack(PLAGUE_LEECH, vUnit)
			end
		end
	end
end